<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<title>彩票开启管理</title>
<%@include file="/WEB-INF/base.jspf"%>
<style>
#test1 {
	margin: 2px;
	height: 37px;
}

#test2 {
	margin: 2px;
	height: 37px;
}

	.modal-dialog {
		max-width: 1000px;
	}
#qblx {
	margin: 2px;
	width:90px;
	height: 37px;
}

#zflx {
	margin: 2px;
	height: 37px;
}
 
 #hymc {
	margin: 2px;
	height: 37px;
} 

#table_id_example_paginate{
 margin-right:100px;
}
.class-input-pageNumber{
    
	width:40px;
	height:23px;
	position: absolute;
	right:55px;
	top:12px;
}
.class-span-searchBtn{
	
	height:24px;
	width:36px;
	font-size:14px;
	text-algin:center;
	line-height:25px;
	padding:0!important;
	position: absolute;
	right:15px;
	top:12px;
}
.dataTables_length{
	margin-top:12px;
	margin-left:50px;
}
.tableSearch{
    position: relative;
}
.layui-inline-sy {
    height:37px;
}
.layui-inline {
	margin-top:15px;
}
.layui-inline-sy.layui-inline-sy-xiala{
    width:95px;
    text-align: center;
}
.layui-inline-dd {
	margin-top: 40px;
}
table th,table tr,table td {
text-align: center;
vertical-align:middle;
}
.div-c-caizhongGetDataWrapper {
	display:flex;
	align-items:center;
	justify-content:flex-end;
}
.class-input-pageNumberTwo,.class-span-searchBtnTwo{
	display: none;
}
</style>
</head>
<body class="layui-layout-body">
		<div> 
			<div class="layui-inline">
				<input class="layui-inline-sy" type="text" id="hymc-huiyuanzhanghao" placeholder="彩种名称">
					<button class="layui-btn layui-btn-radius" id="button-i-searchTableContent">查询</button>
					<button class="layui-btn layui-btn-radius" id="button-i-resetTableContent">重置</button>
			</div>
			<div class="div-c-caizhongGetDataWrapper">
				<span style="margin-right:16px;font-weight:bold;">彩种爬取数据开关</span>
			</div>
			<div class="layui-inline-dd">
				<table id="table_id_example" class="class-tableDataTable class-table-needClick display table table-striped table-bordered table-hover">
					<thead>
						<tr>
							<th class="id-edit-td"></th>
							<th class="name-edit-td">彩种名称</th>
							<th class="type-edit-td">频率类型</th>
							<th class="types-edit-td">范围类型</th>
							<th class="des-edit-td">彩种描述</th>
							<th class="whetherOrNotToCode-edit-td">打码操作</th>
							<th class="state-edit-td">彩种操作</th>
						</tr>
					</thead>
					<tbody>
					</tbody>
				</table>
				</div>
			</div>
	<script>
	
		 function  dataTable01(){
			$("#table_id_example").DataTable({
		      // "bPaginate": true,
		      "bLengthChange": true,      
		      "bSort": false,
		      // "bInfo": true,
		      "bAutoWidth": false,
//		         "bServerSide":true,
		      'aLengthMenu':[5, 10],
		       "searching": true, 
		       "dom": "t<'tableinfo'i<'tableSearch'p>l>",
//		    "searching": true,l
		       "language": {//语言设置  
		            "lengthMenu": "每页显示 _MENU_ 条记录",     
		            "zeroRecords": "没有检索到数据",     
		            "sInfo": "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录",     
		            "info": "没有数据",     
		            "oPaginate": {     
		                "sFirst": "首页",     
		                "sPrevious": "前一页",     
		                "sNext": "后一页",     
		                "sLast": "尾页"    
		          	},
		            "search":"",
		            "searchPlaceholder": "请输入关键字",
		            "infoFiltered":   "(从  _MAX_ 记录中搜索出结果)",
		            "infoEmpty":      "没有找到匹配的信息",
		         },
		          "drawCallback": function( settings ) {
		        	 $(".input-c-mySwitch").bootstrapSwitch();
		         }, 
		         "ajax": {
		        	 "type": "post",
		        	 "url": "/czgl/findAllLotteryInfo.do",
		        	 "dataSrc": function(json) {
		        		 var newJson = json.data;
		        		 for (var i = 0; i < newJson.length; i++) {
			         			 var item = newJson[i];
			         			 var stateValue = "";
			         			 var codeState = "";
			        			 if (item.state == "1") {
			        				 stateValue = "checked";
			        			 } 
			         			 if (item.whetherOrNotToCode == "1") {
			         				codeState = "checked";
			        			 }
			         			if(item.types==1){
			         				item.types="系统彩";
			         			}else{
			         				item.types="官方彩";
			         			}
			         			switch(item.type){
				         			case 1:
				         				item.type = "热门彩";
				         				break;
				         			case 2:
				         				item.type = "高频彩";
				         				break;
				         			case 3:
				         				item.type = "低频彩";
				         				break;
			         			}
	         				item.whetherOrNotToCode = "<input class='input-c-mySwitch dm-switch' data-size='small' type='checkbox' " + codeState + " data-on-text='启用' data-on-color='success' data-off-color='danger' data-off-text='禁用' />"
	         				item.state = "<input class='input-c-mySwitch lot-switch' data-size='small' type='checkbox' " + stateValue + " data-on-text='启用' data-on-color='success' data-off-color='danger' data-off-text='禁用' />"
		         			}
		        		 return newJson;
		        		 }
		          	 }, 
		         "columns": [
					 {"data": "id", "className": "hidden-td id-edit-td"},
					 {"data": "name", "className": "name-edit-td"},
					 {"data": "type", "className": "type-edit-td"},
					 {"data": "types", "className": "types-edit-td"},
					 {"data": "des", "className": "des-edit-td"},
					 {"data": "whetherOrNotToCode", "className": "whetherOrNotToCode-edit-td"},
					 {"data": "state", "className": "state-edit-td"}
	             ]
		 		})
			 }	
			 
		 dataTable01();
		 insertSearchBtn();
		 bindSystemSwitch("#table_id_example", ".dm-switch","/czgl/updateLotteryCodeState.do", "whetherOrNotToCode");
		 bindSystemSwitch("#table_id_example", ".lot-switch","/czgl/updateLotteryState.do", "state");
			
			$("#button-i-searchTableContent").on("click", function(event) {
				$.fn.dataTable.ext.search.pop()
				$("#table_id_example").DataTable()
				.column(1).search($("#hymc-huiyuanzhanghao").val())
				.draw()
			})
		 
			$("#button-i-resetTableContent").on("click", function(event) {
				$.fn.dataTable.ext.search.pop();
				$("#table_id_example").DataTable().column(1).search("").draw();
				$("#hymc-huiyuanzhanghao").val("");
			})
			$.ajax({
				url: "/czgl/openCrawlingData.do",
				type:"post",
				data:{},
				dataType:"json",
				success:function(data){
					var state = data.data
					var switchValue
					if (state == "-1" || state == "0") {
						switchValue = ""
					} else {
						switchValue = "checked"
					}
					var switchSelector = "<input class='input-c-mySwitch' data-size='small' type='checkbox' " + switchValue + " data-on-text='开启' data-on-color='success' data-off-color='danger' data-off-text='关闭' />"
					$(".div-c-caizhongGetDataWrapper").append(switchSelector)
					$(".input-c-mySwitch").bootstrapSwitch()
				},
			});
			
		  	$(".div-c-caizhongGetDataWrapper").on("switchChange.bootstrapSwitch", ".input-c-mySwitch", function(e, state) {
				var status = state ? "1" : "0"
				var newRequest = {
					url:"/czgl/openCrawlingData.do",
					type: "post",
					data: {},
					success: function(data) {
						$(e.currentTarget).bootstrapSwitch("state", state, true)
					},
					error: function(status) {
						showNoticeModal("修改状态失败，请稍后重试")
						$(e.currentTarget).bootstrapSwitch("state", !state, true)
					}
				}
				newRequest.data["states"] = status
				ajax(newRequest)
		    })				
			
	</script>
</body>
</html>